package com.nimt.hqgl_idea.service;


import com.nimt.hqgl_idea.entity.GoodsUseRecord;
import com.nimt.hqgl_idea.mapper.GoodsUseRecordMapper;
import com.nimt.hqgl_idea.param.GoodsUseRecordParam;
import com.nimt.hqgl_idea.util.ErrorEnum;
import com.nimt.hqgl_idea.util.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsUseRecordServiceImpl implements GoodsUseRecordService {
    @Autowired
    GoodsUseRecordMapper goodsUseRecordMapper;

    @Override
    public ResponseBody query(GoodsUseRecordParam goodsUseRecordParam) {
        ResponseBody responseBody = null;
        goodsUseRecordParam.setTotalCount(goodsUseRecordMapper.count(goodsUseRecordParam.getUserId(),goodsUseRecordParam.getKeywords()));
        int start = (goodsUseRecordParam.getCurrentPage()-1)*goodsUseRecordParam.getPageSize();
        List<GoodsUseRecord> goodsUseRecordList = goodsUseRecordMapper.selectAll(start, goodsUseRecordParam.getPageSize(), goodsUseRecordParam.getUserId(),goodsUseRecordParam.getKeywords());
        if(goodsUseRecordList==null || goodsUseRecordList.size() == 0){
            responseBody = new ResponseBody(ErrorEnum.No_More_Data);
        }else {
            goodsUseRecordParam.setData(goodsUseRecordList);
            responseBody = new ResponseBody(goodsUseRecordParam);
        }
        return responseBody;
    }

    @Override
    public ResponseBody del(Integer id) {
        goodsUseRecordMapper.delete(id);
        return new ResponseBody("删除成功!");
    }
}
